package com.lg.dborder2;

import lombok.extern.slf4j.Slf4j;

import java.io.DataInputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

@Slf4j
public class MainFrame {
    public MainFrame() {
        log.info("MainFrme init");
        try {
            ServerSocket serverSocket = new ServerSocket(8888);
            while (true){
                Socket socket = serverSocket.accept();
                AcceptTread acceptTread = new AcceptTread(socket);
                acceptTread.start();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    //新建个内部类
    class AcceptTread extends Thread {
        Socket socket;

        public AcceptTread(Socket socket) {
            this.socket = socket;
        }

        public void run() {
            try {
                DataInputStream dataInputStream = new DataInputStream(socket.getInputStream());
                //不停的接受
                while (true) {
                    String msg = dataInputStream.readUTF();
                    log.info("msg{}", msg);
                }

            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
